home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / emsif24a.zip / EMSTEST2.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  42KB  |  1,063 lines

  1. /***************************************************************************
  2. *   emstest2.c                                                             *
  3. *   MODULE:  EMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.2                                                           *
  6. *   DATE:    12/01/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires emsif.h, testutil.h, and emstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.0A.                   *
  12. *                                                                          *
  13. *   Regression test and example for EMSIF. See EMSTEST.C for more detail.  *
  14. *                                                                          *
  15. ***************************************************************************/
  16.  
  17. /*
  18. ** system includes <>
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25.  
  26. /*
  27. ** custom includes ""
  28. */
  29.  
  30. #include "testutil.h"
  31.  
  32. #include "emsif.h"
  33. #include "emstest.h"
  34.  
  35.  
  36. /*
  37. ** local #defines
  38. */
  39.  
  40. #define UCF                      unsigned char far
  41.  
  42. /*
  43. ** Checks to see if a region of memory is still incrementing word values,
  44. ** handles cleanup and exit if not.
  45. */
  46. #define WORDCHECK(buf, len, msg)                                \
  47.     if (farincwordcheck((UCF *) (buf), (len), 0) != 0) {        \
  48.         printf("Copy corrupted %s.\n", (msg)); EMMfree(handle); \
  49.         free(testbuf); exit(3); }
  50.  
  51. /*
  52. ** Check source and destination buffers, respectively.
  53. */
  54. #define SRCWORDCHECK(buf, len)    WORDCHECK(buf, len, "source buffer")
  55. #define CPYWORDCHECK(buf, len)    WORDCHECK(buf, len, "copied bytes")
  56.  
  57. /*
  58. ** Checks to see if a region of memory is still filled with a given value,
  59. ** handles cleanup and exit if not.
  60. */
  61. #define MEMCHECK(buf, len, val)                          \
  62.     if (farmemcheck((UCF *) (buf), (len), (val)) != 0) { \
  63.         printf("Copy corrupted destination.\n");         \
  64.         EMMfree(handle); free(testbuf); exit(3); }
  65.  
  66. /*
  67. ** Checks buffer for nonzero values.
  68. */
  69. #define ZEROCHECK(buf, len)       MEMCHECK(buf, len, '\0')
  70.  
  71. /*
  72. ** Compares two regions of memory, handles cleanup and exit if not the same.
  73. */
  74. #define MEMCMP(buf1, buf2, len)                                          \
  75.     if (FMEMCMP((void far *) (buf1), (void far *) (buf2), (len)) != 0) { \
  76.         printf("Copy corrupted copied bytes.\n"); EMMfree(handle);       \
  77.         free(testbuf); exit(3); }
  78.  
  79.  
  80. /*
  81. ** misc: copyright strings, version macros, etc.
  82. */
  83.  
  84. /*
  85. ** typedefs
  86. */
  87.  
  88. /*
  89. ** global variables
  90. */
  91.  
  92. /* see EMSTEST.C for info */
  93. extern int testno;
  94. extern unsigned char far *frameptr[];
  95. extern char *gblmsg;
  96.  
  97.  
  98. /*
  99. ** static globals
  100. */
  101.  
  102. /*
  103. ** function prototypes
  104. */
  105.  
  106. static void do_nshortcopy_tests(void);
  107. static void do_ishortcopy_tests(void);
  108.  
  109.  
  110. /*
  111. ** functions
  112. */
  113.  
  114.  
  115. /***************************************************************************
  116. *   FUNCTION: DO_SHORTCOPY_TESTS                                           *
  117. *                                                                          *
  118. *   DESCRIPTION:                                                           *
  119. *                                                                          *
  120. *       Central dispatching function for short copy tests.                 *
  121. *                                                                          *
  122. *   ENTRY:                                                                 *
  123. *                                                                          *
  124. *       Void.                                                              *
  125. *                                                                          *
  126. *   EXIT:                                                                  *
  127. *                                                                          *
  128. *       Void.                                                              *
  129. *                                                                          *
  130. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  131. *                                                                          *
  132. ***************************************************************************/
  133. void do_shortcopy_tests(void)
  134. {
  135.     do_nshortcopy_tests();
  136.     do_ishortcopy_tests();
  137.     return;
  138. } /* end of do_shortcopy_tests() */
  139.  
  140.  
  141. /***************************************************************************
  142. *   FUNCTION: DO_NSHORTCOPY_TESTS  (STATIC)                                *
  143. *                                                                          *
  144. *   DESCRIPTION:                                                           *
  145. *                                                                          *
  146. *       Tests EMSIF functions EMMcopyto() and EMMcopyfrom() with copies    *
  147. *       shorter than one EMS page ( <= 16384 bytes ).                      *
  148. *                                                                          *
  149. *   ENTRY:                                                                 *
  150. *                                                                          *
  151. *       Void.                                                              *
  152. *                                                                          *
  153. *   EXIT:                                                                  *
  154. *                                                                          *
  155. *       Void.                                                              *
  156. *                                                                          *
  157. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  158. *                                                                          *
  159. ***************************************************************************/
  160. static void do_nshortcopy_tests(void)
  161. {
  162.     unsigned char *testbuf;
  163.     int handle;
  164.     int status;
  165.     unsigned long ticks, totticks;
  166.     int loop;
  167.  
  168.     /* allocate memory to test against */
  169.     testbuf = (unsigned char *) malloc(16384);
  170.     if (testbuf == (unsigned char *) NULL)
  171.     {
  172.         printf("Cannot allocate test memory. Aborting.\n");
  173.         exit(1);
  174.     }
  175.  
  176.     /* now allocate a page of EMS to test with */
  177.     handle = test_EMMallocpages(1);
  178.  
  179.     /* fill test buffer with incrementing word pattern */
  180.     farincwordfill((UCF *) testbuf, 16384, 0);
  181.  
  182.     /* fill EMS page with a different pattern */
  183.     test_EMMmappage(0, handle, 0);
  184.     FMEMSET(frameptr[0], 0, 16384);
  185.  
  186.     /* try a bad copy first */
  187.     TESTHEADER();
  188.     printf("Calling EMMcopyto() with bad offset.\n");
  189.     printf("Should fail.\n");
  190.     status = EMMcopyto(5L, (UCF *) testbuf, handle, 20000L);
  191.     nofailcheck("EMMcopyto()", status, testbuf, handle, 0);
  192.     weirdretchk("EMMcopyto()", status, testbuf, handle, 0);
  193.     weirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  194.     SRCWORDCHECK(testbuf, 16384);
  195.     test_EMMmappage(0, handle, 0);
  196.     ZEROCHECK(frameptr[0], 16384);
  197.     printf("EMMcopyto() failed OK.\n");
  198.     TESTTAILER();
  199.  
  200.     /* and another */
  201.     TESTHEADER();
  202.     printf("Calling EMMcopyto() with block that runs off end of EMS.\n");
  203.     printf("Should fail.\n");
  204.     status = EMMcopyto(500L, (UCF *) testbuf, handle, 16000L);
  205.     nofailcheck("EMMcopyto()", status, testbuf, handle, 0);
  206.     weirdretchk("EMMcopyto()", status, testbuf, handle, 0);
  207.     weirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  208.     SRCWORDCHECK(testbuf, 16384);
  209.     test_EMMmappage(0, handle, 0);
  210.     ZEROCHECK(frameptr[0], 16384);
  211.     printf("EMMcopyto() failed OK.\n");
  212.     TESTTAILER();
  213.  
  214.     /* test zero-length copy */
  215.     TESTHEADER();
  216.     printf("Calling EMMc